<extend name="./public/frame.html"/>
<block name="content">
    <blockquote class="layui-elem-quote search">
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="invoice_sn" placeholder="发票流水号">
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input date" readonly id="start" placeholder="申请时间-起">
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input date" readonly id="end" placeholder="申请时间-止">
        </div>
        <div class="layui-input-inline" style="width: 100px;">
            <select lay-verify="required" lay-search="" class="layui-input" id="is_free">
                <option value="">是否包邮</option>
                <option value="1">是</option>
                <option value="2">否</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 100px;">
            <select lay-verify="required" lay-search="" class="layui-input" id="invoice_status">
                <option value="">发票状态</option>
                <volist name="invoice_status" id="state">
                    <option value="{$key}">{$state}</option>
                </volist>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 100px;">
            <button class="layui-btn" data-type="search">搜索</button>
        </div>
    </blockquote>
    <table class="layui-table" lay-data="{ height:'auto', url:'{:url('invoice/tableInvoice')}', page: true, limit: '10', id:'invoice'}" lay-filter="invoice">
        <thead>
        <tr>
            <th lay-data="{field:'invoice_common_id', width:70, fixed: true, sort: true,align:'center'}">ID</th>
            <th lay-data="{field:'uid', width:100,align:'center'}">UID</th>
            <th lay-data="{field:'user_phone', width:120,align:'center'}">手机号</th>
            <th lay-data="{field:'email', width:200,align:'center'}">邮箱</th>
            <th lay-data="{field:'invoice_sn', width:200,align:'center'}">发票记录流水号</th>
            <th lay-data="{field:'invoice_type_name', width:120,align:'center'}">发票类型</th>
            <th lay-data="{field:'title_type_name', width:120,align:'center'}">发票抬头类型</th>
            <th lay-data="{field:'title', width:120,align:'center'}">发票标题</th>
            <th lay-data="{field:'money', width:100, align:'center', templet: '#moneyTpl'}">发票金额</th>
            <th lay-data="{field:'statusName', width:120,align:'center'}">开票状态</th>
            <th lay-data="{field:'add_time', width:160,align:'center'}">申请时间</th>
            <!--th lay-data="{field:'statusName', width:100,align:'center'}">发票状态</th>
            <th lay-data="{field:'is_free', width:100,align:'center', templet: '#freeTpl'}">是否包邮</th>-->
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:100, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="detail">查看</a>
        <!--{{#if(d.invoice_status=='2'){ }}
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="post">&nbsp;邮 寄&nbsp;</a>
        {{#}else if(d.invoice_status=='3'){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled">已邮寄</a>
        {{#}else if(d.invoice_status=='1'){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled">待付款</a>
        {{#}else{ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled">已取消</a>
        {{#} }}-->
    </script>
    <script type="text/html" id="moneyTpl">
        {{#if(d.money>=0){}}
        {{(d.money/100).toFixed(2)}}
        {{#}}}
    </script>
    <!--<script type="text/html" id="freeTpl">
        {{#if(d.is_free==1){}}是
        {{#}else{ }}否
        {{#}}}
    </script>-->
    <script type="application/javascript">
        layui.use(['table', 'form', 'laydate'], function () {
            var table = layui.table
                , form = layui.form
                , laydate = layui.laydate;
            lay('.date').each(function () {
                laydate.render({elem: this, type: 'date', trigger: 'click'});
            });

            //监听工具条
            table.on('tool(invoice)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var invoice_common_id = data.invoice_common_id;
                if (layEvent === 'detail') {
                    layer.open({
                        type: 2,
                        title: '申请发票信息查看',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['95%', '95%'],
                        content: '{:url("/admin/invoice/detailInvoice","invoice_common_id=")}' + invoice_common_id //iframe的url
                    });
                }/*else if (layEvent === 'post') {
                    layer.open({
                        type: 2,
                        title: '添加编号为' + data.invoice_sn + '的发票快递信息',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['95%', '95%'],
                        content: '{:url("/admin/invoice/addExpress","invoice_common_id=")}' + invoice_common_id, //iframe的url
                        cancel: function (index, layero) {
                            table.reload('invoice', {url: '/admin/invoice/tableInvoice'});
                        }
                    });
                }*/
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var invoice_sn  = $('#invoice_sn').val();
                    var start       = $('#start').val();
                    var end         = $('#end').val();
                    var is_free     = $('#is_free').val();
                    var invoice_status = $('#invoice_status').val();
                    var order_sn = $('#order_sn').val();
                    table.reload('invoice', {
                        url: '/admin/invoice/tableInvoice',
                        where: {
                            invoice_sn: invoice_sn,
                            start: start,
                            end: end,
                            is_free: is_free,
                            invoice_status: invoice_status,
                            order_sn: order_sn
                        } //设定异步数据接口的额外参数
                    });
                }
            };

            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</block>
